package com.changhai.diabetes.service.impl;

import java.util.List;

import com.changhai.diabetes.model.Personal;
import com.changhai.diabetes.service.PersonalService;
import com.changhai.diabetes.util.Constants;

/**
 * 患者个人史信息
 * 
 * @author Andy
 * 
 */
public class PersonalServiceImpl extends CommonServiceImpl implements PersonalService {

	public Personal searchByPatientId(Long patientId){	 
		List list = this.getList(Constants.DS_CHANGHAI, "personal.getByPatientId", patientId);	 
		if (list != null && list.size()>0) {
			return (Personal) list.get(0);
		} else {
			Personal p = new Personal();
			p.setPatientid(patientId);
			return p;
		}
	}
	
	public void saveEditPersonal(Personal personal){
		if (personal != null) {
			if(personal.getPersonalid()!=null){
				this.updateObject(Constants.DS_CHANGHAI, "personal.updateByPrimaryKey", personal);
			}else{
				Long pid = this.saveNewPersonal(personal);
				if (pid != null && pid > 0) {
					personal.setPersonalid(pid);
					this.updateObject(Constants.DS_CHANGHAI, "personal.updateByPrimaryKey", personal);
				}
			}
		}
	}
	
	public Long saveNewPersonal(Personal personal) {
		Integer id = 0;
		if (personal != null && personal.getPatientid()!=null) {
			id = this.insertObjectID(Constants.DS_CHANGHAI, "personal.insert", personal);
		}
		return new Long(id);
	}
}
